#!/usr/bin/perl -w
#
# Copyright(c) Plink Limited 2010. All rights reserved.
#
# $Header:$
#
# $Log:$
# 
# Author:      Jeremy Banks
#
# Description: A source
#

#----------------------------------------------------------------------
# External Modules
#----------------------------------------------------------------------

package XMLTV::Source;

use strict;

use XMLTV::Logger;

#---------------------------------------------------------------------------
# Globals
#---------------------------------------------------------------------------

use constant SINGLE_TYPE   => 1;
use constant MULTIPLE_TYPE => 2;

#---------------------------------------------------------------------------
# Constructor
#---------------------------------------------------------------------------

sub new
{
   my $class = shift;
   my $self = bless {}, $class;

   eval "\$self->{_$_} = undef" for qw/name prefix type adjust_start enabled
                                       page_hours tz_adjust/;
   $self->{_channels} = [];
   $self->{_output_channels} = [];
   return $self;
}

# Setters and getters

#---------------------------------------------------------------------------
# Setter/getter for name
#---------------------------------------------------------------------------

sub name
{
   my ($self, $value) = @_;
   $self->{_name} = $value if $value;
   return $self->{_name};
}

#---------------------------------------------------------------------------
# Setter/getter for prefix
#---------------------------------------------------------------------------

sub prefix
{
   my ($self, $value) = @_;
   $self->{_prefix} = lc $value if $value;
   return $self->{_prefix};
}

#---------------------------------------------------------------------------
# Setter/getter for type
#---------------------------------------------------------------------------

sub type
{
   my ($self, $value) = @_;
   if ($value)
   {
      if (SINGLE_TYPE != $value and MULTIPLE_TYPE != $value)
      {
         XMLTV::Logger->instance()->die("Invalid type for Source::type: $value");
      }
      $self->{_type} = $value;
   }
   return $self->{_type};
}

#---------------------------------------------------------------------------
# Setter/getter for adjust start time
#---------------------------------------------------------------------------

sub adjust_start_time
{
   my ($self, $value) = @_;
   $self->{_adjust_start} = $value if $value;
   return $self->{_adjust_start};
}

#---------------------------------------------------------------------------
# Setter/getter for the timezone minute adjustment
#---------------------------------------------------------------------------

sub timezone_minute_adjust
{
   my ($self, $value) = @_;
   $self->{_tz_adjust} = $value if $value;
   return $self->{_tz_adjust};
}

#---------------------------------------------------------------------------
# Setter/getter for enabled
#---------------------------------------------------------------------------

sub enabled
{
   my ($self, $value) = @_;
   $self->{_enabled} = $value if $value;
   return $self->{_enabled};
}

#---------------------------------------------------------------------------
# Setter/getter for support channels
#---------------------------------------------------------------------------

sub support_channels
{
   my ($self, $value) = @_;
   $self->{_channels} = $value if $value;
   return $self->{_channels};
}

#---------------------------------------------------------------------------
# Setter/getter for output channels
#---------------------------------------------------------------------------

sub output_channels
{
   my ($self, $value) = @_;
   $self->{_output_channels} = $value if $value;
   return $self->{_output_channels};
}

#---------------------------------------------------------------------------
# Setter/getter for hours per page
#---------------------------------------------------------------------------

sub hours_per_page
{
   my ($self, $value) = @_;
   $self->{_page_hours} = $value if $value;
   return $self->{_page_hours};
}

#----------------------------------------------------------------------
# String representation
#----------------------------------------------------------------------

sub to_string
{
   my $self = shift;

   my $str = "XMLTV::Source:\n";
   $str .= "\t$_: " . ($self->{"_$_"} || "undef") . "\n"
       for qw/name prefix type adjust_start enabled
                                       channels output_channels page_hours
                                       tz_adjust/;
   return $str;
}

1;
